﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RLGDashboard
{
    public partial class ColorComboBox : ComboBox
    {
        public ColorComboBox()
        {
            InitializeComponent();
            this.DrawMode = DrawMode.OwnerDrawFixed;
            this.DropDownStyle = ComboBoxStyle.DropDownList;
           
            ArrayList ColorList = new ArrayList();
            Type colorType = typeof(System.Drawing.Color);
            PropertyInfo[] propInfoList = colorType.GetProperties(BindingFlags.Static |
                                          BindingFlags.DeclaredOnly | BindingFlags.Public);
            foreach (PropertyInfo c in propInfoList)
            {
                this.Items.Add(c.Name);
            } 
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
        }

        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            int index;
            e.DrawBackground();
            if (e.Index == -1)
            {
                index = 0;
            }
            else
            {
                index = e.Index;
            }
            string s = (string) this.Items[index];

            using (Brush b = new SolidBrush(Color.FromName(s)))
            {
                e.Graphics.DrawRectangle(Pens.Black, 2, e.Bounds.Top + 1, 20, 12);
                e.Graphics.FillRectangle(b, 3, e.Bounds.Top + 2, 19, 11);
                e.Graphics.DrawString(s, new Font("Arial", 9, FontStyle.Regular), Brushes.Black, 23, e.Bounds.Top + 1); 
            }

            e.DrawFocusRectangle();
        }
    }
}
